import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap;

public class Main {
	public static void main(String[] args) throws IOException {

		
		String svSource = "/home/xiaoran/Desktop/SVM-Light/model1000.txt";
		
		File finSV = new File(svSource);
		FileInputStream fisSV = new FileInputStream(finSV);
		BufferedReader inSV = new BufferedReader(new InputStreamReader(fisSV));

		HashMap<String, String> sv = new HashMap<String, String>();

		String aLine = null;
		while ((aLine = inSV.readLine()) != null) {
			
			
			String[] arr = aLine.split(" ");
			
			sv.put(arr[1].trim(), arr[2].trim());	
			
			
			System.out.println(arr[1]);
			System.out.println(arr[2]);
			System.out.println(arr[0]);
					
		}
		
		inSV.close();
		
		//above code get support vector
		
		System.out.println("--------------------------------" + sv);
		
		
		
		String source = "/home/xiaoran/Desktop/SVM-Light/past1000.txt";
		
		//String dest = "/home/xiaoran/Desktop/hw3/q1-train-m.txt";

		File fin = new File(source);
		FileInputStream fis = new FileInputStream(fin);
		BufferedReader in = new BufferedReader(new InputStreamReader(fis));

		/*FileWriter fstream = new FileWriter(dest, true);
		BufferedWriter out = new BufferedWriter(fstream);*/

		aLine = null;
		while ((aLine = in.readLine()) != null) {

			//System.out.println(aLine);

			//   8.0541175	1 1:3.9071198 2:-1.4269543
			String[] arr = aLine.split("	");
			
			String otype = arr[0];
			String second = arr[1];
			
			String[] arr2 = second.split(" ");
			String rtype = arr2[0];
			
			String x = arr2[1].trim().split(":")[1];
			String y = arr2[2].trim().split(":")[1];
			
			//System.out.println("---------------" + arr2[1]);
			//System.out.println(arr2[2]);
			
			boolean isSupportVector = false;
			
			if(sv.containsKey(arr2[1].trim()) || sv.containsValue(arr2[2].trim())){
				//System.out.println("support ");
				//System.out.println("support"+ arr2[1]);
				//System.out.println("support "+arr2[2]);
				isSupportVector = true;
			}
			
			
			if(rtype.charAt(0) == '-'){
				
				if(isSupportVector){
					//circle red
					if(otype.charAt(0) == '-'){
						System.out.println("\\draw [red]("+ new Double(x)*0.6 +","+ new Double(y)*0.6+") circle (0.09);");
					}else{
						System.out.println("\\draw [fill=red]("+ new Double(x)*0.6 +","+ new Double(y)*0.6+") circle (0.09);");
					}
					
					
					
				}else{

					if(otype.charAt(0) == '-'){
						//circle empty
						System.out.println("\\draw ("+ new Double(x)*0.6 +","+ new Double(y)*0.6+") circle (0.09);");
						//System.out.println("\\draw ("+x +","+ y+") circle (0.09);");
					}else{
						//circle full
						System.out.println("\\draw [fill=black] ("+ new Double(x)*0.6  +","+ new Double(y)*0.6+") circle (0.09);");
						//System.out.println("\\draw [fill=black] ("+ x  +","+ y+") circle (0.09);");

					}
				}
				
				
				
				
			}else{
				
				if(isSupportVector){
					
					if(otype.charAt(0) == '-'){
						System.out.println("\\draw [fill=red]("+ new Double(x)*0.6  +","+ new Double(y)*0.6+") \\polygon{3}{0.06};");
					}else{
						System.out.println("\\draw [red]("+ new Double(x)*0.6  +","+ new Double(y)*0.6+") \\polygon{3}{0.06};");
					}
					
				

				}else{
					if(otype.charAt(0) == '-'){
						//triange full
						System.out.println("\\draw [fill=black]("+ new Double(x)*0.6  +","+ new Double(y)*0.6+") \\polygon{3}{0.06};");
						//System.out.println("\\draw [fill=black]("+x +","+ y+") \\polygon{3}{0.06};");

					}else{
						//triangle empty
						System.out.println("\\draw ("+ new Double(x)*0.6  +","+ new Double(y)*0.6+") \\polygon{3}{0.06};");
						//System.out.println("\\draw ("+x +","+ y+") \\polygon{3}{0.06};");

					}
				}
				
				
			}
			
			
		
			
			
			
			/*	
				out.write(arr[0]);
				out.write(",");
				out.write(arr[1]);
				out.write(",");
				out.write(arr[2]);
				out.write(",");
				out.newLine();*/
		
			

			// Process each line and add output to Dest.txt file
			
		}

		// do not forget to close the buffer reader
		in.close();
		//out.close();
		
		
		
	}

}
/*
 * 
 * 
 * 
 * circle empty     \draw ("+ x +","+ y+") circle (0.09);
 * circle full      \draw [fill=black] ("+ x +","+ y+") circle (0.09);
 * triangle empty   \draw ("+ x +","+ y+") \polygon{3}{0.06};
 * triangle full    \draw [fill=black]("+ x +","+ y+") \polygon{3}{0.06};
 * 
\draw (0,0) \polygon{3}{0.06};
\draw (3.4,0) \polygon{4}{0.07};
\draw[red] (6,0) circle (0.09);
 * 
 * 
 */
